# -*- coding: utf-8 -*-#
#-------------------------------------------------------------------------------
# 建立者:        黄周云  
# Name:         test10
# Description:  例11.8
# Author:       ASUS
# Date:         2019/3/25
#-------------------------------------------------------------------------------


#"^"表示匹配字符串的开始
#"$"表示匹配字符串的结束
#"\b"表示单词的边界，这里的边界是指单词两边是空格或标点符号,字符也可以看着是单词，所以字符不是边界

import re
m = re.search("^The","The end.")
print(m)
if m is not None:
    print(m.group())
m = re.search("^The","end. The")
print(m)

m = re.search("The$","end. The")
print(m)
if m is not None:
    print(m.group())
m = re.search("The$","The end.")
print(m)

#this的左边必须有边界
m = re.search(r"\bthis","What's this?")
print(m)
if m is not None:
    print(m.group())
#this的左右两边都有边界
m = re.search(r"\bthis\b","What's this?")
print(m)
if m is not None:
    print(m.group())
m = re.search(r"\bthis\b","What'sthis?")
print(m)
